/**
 * user 验证规则模块
 */
const joi = require('joi')

// 用户登录注册验证规则
const username = joi.string().alphanum().min(3).max(18).required().error(new Error('用户名不合法'))
const password = joi.string().pattern(/^\S{3,18}$/).required().error(new Error('密码不合法'))
const email = joi.string().email().required().error(new Error('邮箱不合法'))
const captcha = joi.string()
const isCaptcha = joi.boolean()

// 注册的验证规则对象
exports.reg_schema = {
  body: {
    username,
    password,
    email,
  }
}

// 登录的验证规则对象
exports.login_schema = {
  body: {
    username,
    password,
    captcha,
    isCaptcha
  }
}